package com.linwen.excise.base;

/**
 * @author : linwen
 * @date : 下午11:29 2021/9/26
 */
public class 阶乘 {

    public static void main(String[] args) {
        long t1 = System.currentTimeMillis();
        long result1 = jiecheng(10);
        System.out.println(result1);
        long t2 = System.currentTimeMillis();
        System.out.println("耗时:"+(t2-t1));

        long t3 = System.currentTimeMillis();
        long result2 = xunhuan(10);
        System.out.println(result2);
        long t4 = System.currentTimeMillis();
        System.out.println("耗时:"+(t4-t3));

    }
    private static long xunhuan(int i) {
        long result = 1;
        while(i>=1) {
            result *= i;
            i--;
        }
        return result;
    }
    private static long jiecheng(int i) {
        if(i==1) {
            return 1;
        }else {
            return i*jiecheng(i-1);
        }
    }

}
